<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/13
 * Time: 11:33
 */

require '../tools/Dbtools.php';

$cardno = $_POST['cardno'];
$username = $_POST['username'];
$usercode = $_POST['usercode'];
$money = $_POST['money'];
$pwd1 = $_POST['pwd1'];
$pwd2 = $_POST['pwd2'];

Dbtools::InitDb();

$data = DbTools::select("SELECT * from bankcard where CardNo = '$cardno'");
if(count($data)!=0){
    echo '该卡已经注册';
    echo '<br />';
    echo '<a href="insertCard.php">返回</a>';
    die;
}

if ($pwd1 != $pwd2){
    echo '两次输入的密码不一致';
    echo '<br />';
    echo '<a href="insertCard.php">重新输入</a>';
    die;
}else {

    $data = Dbtools::select("SELECT AccountId from accountinfo where RealName = '$username' and AccountCode = '$usercode'");

    if(empty($data[0]['AccountId'])){
        echo '名字或者身份证号码错误，或者不匹配，或者不存在该用户';
        echo '<br />';
        echo '<a href="insertCard.php">重新输入</a>';
    }else{
        //到这里，说明正常
        $AccountId = $data[0]['AccountId'];
        $sql = "INSERT INTO bankcard(CardNo,AccountId,CardPwd,CardMoney,CardState,CardTime) VALUES('$cardno',$AccountId,'$pwd1',$money,0,now())";
        $resutl = DbTools::noSelect($sql);
        if($resutl['status']){
            echo '卡信息录入成功';
            echo '<br />';
            echo '<a href="administrator.php">返回</a>';
        }else{
            echo '卡信息录入失败： '.$resutl['message'];
        }
    }

}
//关闭数据库连接
DbTools::close();



